package kitrobot.com.bed.Service;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import kitrobot.com.bed.StreamTools;

public class SelepoService {
    public static String SelepoByClientPost(String bid,String appuser_id,String token){
        try{
            HttpClient client=new DefaultHttpClient();
            String path="http://47.106.217.3:8360/app/permission/detail";
            HttpPost httpPost=new HttpPost(path);
            List<NameValuePair>parmeters=new ArrayList<NameValuePair>();
            parmeters.add(new BasicNameValuePair("bed_id",bid));
            parmeters.add(new BasicNameValuePair("appuser_id",appuser_id));
            httpPost.setEntity(new UrlEncodedFormEntity(parmeters,"UTF-8"));
            httpPost.addHeader("Authorization",token);
            HttpResponse response=client.execute(httpPost);
            int code=response.getStatusLine().getStatusCode();
            if(code==200){
                InputStream is=response.getEntity().getContent();
                String text= StreamTools.readInputStream(is);
                return text;

            }
            else{
                return null;
            }
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
